/**
 * @LoginServiceImpl.java
 * Copyright (c) 2010, Strong. All Rights Reserved.
 */
package cn.strong.scweb.sysmgr.service.impl;

import java.util.List;

import cn.strong.framework.business.BusinessException;
import cn.strong.scweb.common.service.impl.CommonServiceImpl;
import cn.strong.scweb.common.util.Constants;
import cn.strong.scweb.common.util.Constants4Method;
import cn.strong.scweb.sysmgr.action.LoginAction;
import cn.strong.scweb.sysmgr.entity.ScUserEntity;
import cn.strong.scweb.sysmgr.service.LoginService;

/**
 * @author lilanfei
 * @version 1.0
 * @since 2010-2-4
 */
public class LoginServiceImpl extends CommonServiceImpl implements LoginService {

    /* (non-Javadoc)
     * @see cn.strong.scweb.sysmgr.service.LoginService#doLogin(cn.strong.scweb.sysmgr.action.LoginAction)
     */
    @SuppressWarnings("unchecked")
    public boolean doLogin(LoginAction loginAction) {
        
        ScUserEntity scUserEntity = new ScUserEntity();
        scUserEntity.setUsername(loginAction.getScUserEntity().getUsername());
        scUserEntity.setPassword(loginAction.getScUserEntity().getPassword());
        
        List scUserList = this.getCommonDao().selectList(Constants4Method.DO_LOGIN, scUserEntity);
        
        if (scUserList != null && scUserList.size() > 0) {
            return true;
        }
        
        return false;
    }

    /* (non-Javadoc)
     * @see cn.strong.scweb.sysmgr.service.LoginService#addUser(cn.strong.scweb.sysmgr.action.LoginAction)
     */
    public void addUser(LoginAction loginAction) throws Exception {
        try {
            this.getCommonDao().insert(Constants.INSERT_SC_USER, loginAction.getScUserEntity1());
            this.getCommonDao().insert(Constants.INSERT_SC_USER, loginAction.getScUserEntity2());
        } catch (Exception e) {
            throw new BusinessException();
        }
    }

    /* (non-Javadoc)
     * @see cn.strong.scweb.sysmgr.service.LoginService#deleteUser(cn.strong.scweb.sysmgr.action.LoginAction)
     */
    public void deleteUser(LoginAction loginAction) throws Exception {
        try {
            this.getCommonDao().insert(Constants.DElETE_SC_USER, loginAction.getScUserEntity1());
        } catch (Exception e) {
            throw new BusinessException();
        }
    }
}
